package com.grgbanking.it.common.util.poi;



import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;

/**
 * Shell组装者
 * 
 * POIShellContructor
 * 
 * @author 潘广伟
 * @Email p_3er@qq.com
 * @Date 2015-1-9 下午3:53:16
 * 
 * @version 1.0.0
 *
 */
public class POIShellContructor {
	private HSSFSheet sheet;
	
	public POIShellContructor(HSSFSheet sheet){
		this.sheet = sheet;
	}
	
	/**
	 * 设置抬头
	 * setHeader
	 * 
	 * @param headerIndex
	 * @param headers 
	 * @exception 
	 * @since  1.0.0
	 */
	public void setHeader(Integer headerIndex,String[] headers) {
		//产生表格标题行
		HSSFRow row = createRow(headerIndex);
		for (int i = 0; i < headers.length; i++) {
			HSSFCell cell = row.createCell(i);
			HSSFRichTextString text = new HSSFRichTextString(headers[i]);
			cell.setCellValue(text);
			this.setCellText(row, i, headers[i]);
		}
	}
	/**
	 * 设置单元格文本
	 * setCellText
	 * 
	 * @param row
	 * @param cellIndex
	 * @param value 
	 * @exception 
	 * @since  1.0.0
	 */
	public void setCellText(HSSFRow row,Integer cellIndex,String value){
		HSSFCell cell = row.createCell(cellIndex);
		HSSFRichTextString text = new HSSFRichTextString(value);
		cell.setCellValue(text);
	}
	/**
	 * 创建一行
	 * createRow
	 * 
	 * @param rowIndex
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	public HSSFRow createRow(Integer rowIndex){
		return sheet.createRow(rowIndex);
	}
	/**
	 * 设置默认列宽
	 * setDefaultColumnWidth
	 * 
	 * @param width 
	 * @exception 
	 * @since  1.0.0
	 */
	public void setDefaultColumnWidth(Integer width){
		sheet.setDefaultColumnWidth(width);
	}
}
